<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>分类管理</title>
  {include file="common/_require"}

  <script>
    var currentHeaderNavItem = 'Post-{$Request.param.type|default="1"}';
    var currentLeftNavItem = 'category-{$Request.param.type|default="1"}';
  </script>
</head>

<body class="layui-layout-body">

  <div class="layui-layout layui-layout-admin">
    {include file="common/_header"}

    {include file="common/left_post"}

    <div class="layui-body">

      <div style="padding:15px">
        <div class="main-header">
          <span class="layui-breadcrumb">
            <a>首页</a>
            <a><cite>分类管理</cite></a>
          </span>
        </div>
        <div class="main-container">
          <div class="layui-col-md6">
            <fieldset class="layui-elem-field">
              <legend>编辑分类</legend>
              <div class="layui-field-box">
                <form class="layui-form" action="{:url('update')}" method="post" lay-filter="*">
                  <input type="hidden" name="id" value="{$category.id}">
                  <div class="layui-form-item">
                    <div class="layui-form-label">分类名称</div>
                    <div class="layui-input-block">
                      <input type="text" name="title" value="{$category.title}" required lay-verify="required" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-form-label">上级分类</div>
                    <div class="layui-input-block">
                      <select name="pid">
                        <option value="0">--无上级分类--</option>
                        {volist name='$list_category' id='vo'}
                        {if $category.id != $vo.id}
                        <option value="{$vo.id}">{:str_repeat('|--',$vo.level)}{$vo.title}</option>
                        {/if}
                        {/volist}

                      </select>     
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-form-label">副标题/描述</div>
                    <div class="layui-input-block">
                      <textarea name="desc" class="layui-textarea">{$category->getData('desc')}</textarea>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-form-label">附图</div>
                    <div class="layui-input-block">
                      <input type="hidden" name="title_img" value="{$category->getData('title_img')}">
                      <div>
                        <div class="layui-btn upload-title-img">上传</div>
                      </div>
                      <div>
                        <img src="{$category.title_img}" class="title-img" style="max-width: 200px;max-height: 200px;;" alt="">
                      </div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-form-label">模板</div>
                    <div class="layui-input-block">
                      <select name="tpl_name">
                        {volist name=':config("view_type.category")' id='view_type'}
                          <option value="{$key}">{$view_type}</option>
                        {/volist}
                      </select>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-form-label">状态</div>
                    <div class="layui-input-block">
                      <input type="radio" name="status" value="1" title="显示">
                      <input type="radio" name="status" value="0" title="不显示">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" submit lay-submit lay-filter="site-info">提交</button>
                  </div>
                </form>
              </div>
            </fieldset>
          </div>
        </div>
      </div>
    </div>


    {include file="common/_footer"}
  </div>

  <script>

    layui.use(['form','upload'],function(){
      var form = layui.form;
      var upload = layui.upload;

      form.val('*',{
        pid:'{$category.pid}',
        tpl_name:'{$category->getData("tpl_name")}',
        status:'{$category->getData("status")}',
      })

      upload.render({
        elem: '.upload-title-img',
        url: '{:url("File/save")}',
        data: {
          type: 4,
          dir: 'article'
        },
        accept: 'images',
        done: function (result) {
          if (result.code == 0) {
            layer.msg('上传成功');
            $('input[name="title_img"]').val(result.data.save_name)
            $('.title-img').attr('src', result.data.src).show();
          } else {
            layer.msg(result.msg)
          }
        }
      })
    })

  </script>
</body>

</html>